package com.yunhe.java.Day12;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by Administrator on 2017/8/5 0005.
 */
public class listpaixu {
    public static void main(String[] args) {
        List<Person> list=new ArrayList();
        Person p1= new Person("王二16",16);
        Person p2= new Person("王二18",18);
        Person p3= new Person("王二26",26);
        Person p4= new Person("王二36",36);
        list.add(p1);
        list.add(p2);
        list.add(p3);
        list.add(p4);
        Collections.sort(list, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                int n=0;
                if(o1.getAge()>o2.getAge()){
                    n=1;
                }else if(o1.getAge()>o2.getAge()){
                    n=-1;
                }
                return n;
            }
        });

        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
         }
}
